<?php
//User interface that allows a user to select an incomplete inspection or start a new inspection.
	include 'commonAccountFunctions.php';
	
	session_start();
	$user = checkAuthentication();
	
	print_header();
?>	
	<div id="topbar">
		<div id="title"> Lab-Check</div>
		<div id="rightbutton"> <a href="index.php" class="noeffect">Log Out</a> </div>
	</div>
	<div id="tributton">
		<div class="links">
			<a href="controlpanel.php">Control Panel</a><a id="pressed" href="newinspection.html">New Inspection</a>
		</div>
	</div>
	

		<?php
			//reads in a specified directory that is in the file folder.
			function readFiles($folderName){
				$fileList="";
				$dir = "../files/" . $folderName;
				if (is_dir($dir)) {
					if ($dh = opendir($dir)) {
						$i = 0;
						while (($file = readdir($dh)) !== false) {
							if($file != "." and $file != ".."){
								$fileList[$i] = trim($file, ".txt");
								$i++;
							}
						}
						closedir($dh);
					}
				}
				return $fileList;
			}
			$inspectionList = readFiles("incompleteInspections");
			$protocolList = readFiles("templates");
			$facilityList = file("../files/facilityList.txt");
		?>
		
	<div id="content">
		<ul class="pageitem" style="padding:5px">
			<li> <strong>UserName:</strong>  <?=$user?> </li>
		</ul>

		<span class="graytitle">Incomplete Inspections:</span>
		<form action="viewCheckList.php" method="post">
		<ul class="pageitem">
			<li class="select"><select name="file">
				<?php
					foreach($inspectionList as $file){ ?>
							<option value="<?=$file?>"> <?=$file ?> </option> <?php 
					} ?>
					</select><span class="arrow"></span> </li>
			</li>
			<li class="button"> <input type="submit" value="Continue" /> </li>
		</ul>
		</form>
	
		<span class="graytitle">New Inspection:</span>
		<form action="viewCheckList.php" enctype="multipart/form-data" method="post">
		<ul class="pageitem">
			<li style="margin:5px"><span class="header">Facility:</span></li>
			<li class="select"><select name="facility">
				<?php foreach($facilityList as $facility){ ?>
						<option value="<?php echo trim($facility);?>_"><?php echo $facility;?></option>
					<?php } ?>
				</select><span class="arrow"></span>
			</li>
			<li> <span> </span></li>
			<li style="margin:5px"><span class="header">Checklist Protocol:</span></li>
			<li class="select"><select name="protocol">
			  <?php foreach($protocolList as $protocol){ ?>
						<option value="<?=$protocol?>"> <?=$protocol ?> </option> <?php 
					} ?>
				</select><span class="arrow"></span> </li>
			<li class="button"> <input type="submit" value="Create" /> </li>
		</ul>
	</div>	
	

<?php
	print_footer();
?>